/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controladores;

import Interfaces.ICtrlRelojSistema;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author Sebas
 */
public class CtrlRelojSistema implements ICtrlRelojSistema{
    
     DateFormat df;
     Timer timer;
    
    private CtrlRelojSistema() {
        
          df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
            df.setCalendar(Calendar.getInstance());
            timer = new Timer();
            timer.schedule(new DoTick(), 0, 1000); 
        
    }
    
    public static CtrlRelojSistema getInstance() {
        return CtrlRelojSistemaHolder.INSTANCE;
    }

    class DoTick extends TimerTask {
            public boolean sigue = true;
        @Override
            public void run() {
                
                Calendar c = df.getCalendar();
            //System.out.println(df.format(c.getTime()));

            c.add(Calendar.SECOND, 1);
            df.setCalendar(c);

        }
    }

    public void cancel() {

        timer.cancel();
    }

    @Override
    public void setReloj(Calendar cal) {

        df.setCalendar(cal);
    }

    @Override
    public Calendar getTime() {

        Calendar cal = df.getCalendar();
        return cal;
    }
    
    private static class CtrlRelojSistemaHolder {

        private static final CtrlRelojSistema INSTANCE = new CtrlRelojSistema();
    }
    
  
    
}
